package com.zzl.study.auth.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: zhangzl
 * @date: 2024/3/14 11:13
 * @version: 1.0
 * @description: 示例Controller
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @GetMapping("/client")
    public Map<String, Object> client(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient oAuth2AuthorizedClient) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Map<String, Object> map = new HashMap<>(2);
        map.put("oAuth2AuthorizedClient", oAuth2AuthorizedClient);
        map.put("authentication", authentication);
        return map;
    }

}
